package com.artisan.spider;

import com.artisan.spider.consts.Consts;
import com.artisan.spider.service.ISpErrorService;
import com.artisan.spider.util.SpiderUtil;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
@Slf4j
public class DffggzDfgfxwjTaskTest01 {

    @Autowired
    ISpErrorService iSpErrorService;

    @Autowired
    SpiderUtil spiderUtil;

    @Test
    public void collectionInfo(){
        try (Playwright playwright = Playwright.create()) {
            String pageUrl = Consts.dfgfxwj;
            Browser browser = playwright.chromium().launch();

            BrowserContext context = browser.newContext();
            Page page = context.newPage();
            page.navigate(String.format(pageUrl, 1));
            int pageNum = Integer.valueOf(page.querySelector(".page").innerText().split("/")[1].replace("页", "").trim());
            page.close();
            context.close();
            for (int i = 1; i <= pageNum; i++) {
                spiderUtil.pageChuli(browser,"dfflgz",pageUrl, i);
            }
        }
    }
}
